<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>许可管理 - Sentinel LDK Licensing</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 15px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        
        .header {
            background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }
        
        .header h1 {
            font-size: 2.5em;
            margin-bottom: 10px;
        }
        
        .header p {
            font-size: 1.1em;
            opacity: 0.9;
        }
        
        .nav-bar {
            background: #f8f9fa;
            padding: 15px 30px;
            border-bottom: 1px solid #e1e5e9;
        }
        
        .nav-bar a {
            color: #666;
            text-decoration: none;
            margin-right: 20px;
            padding: 8px 15px;
            border-radius: 5px;
            transition: background-color 0.3s ease;
        }
        
        .nav-bar a:hover {
            background: #e9ecef;
        }
        
        .nav-bar a.active {
            background: #007bff;
            color: white;
        }
        
        .content {
            padding: 40px;
        }
        
        .section {
            background: #f8f9fa;
            padding: 30px;
            border-radius: 10px;
            margin-bottom: 30px;
        }
        
        .section h2 {
            color: #333;
            margin-bottom: 20px;
            font-size: 1.5em;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: 500;
        }
        
        .form-group input, .form-group select {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #e1e5e9;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s ease;
        }
        
        .form-group input:focus, .form-group select:focus {
            outline: none;
            border-color: #ff6b6b;
            box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1);
        }
        
        .btn {
            background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
            color: white;
            padding: 12px 30px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
            margin-right: 10px;
        }
        
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(255, 107, 107, 0.3);
        }
        
        .btn-secondary {
            background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%);
        }
        
        .btn-secondary:hover {
            box-shadow: 0 10px 20px rgba(108, 117, 125, 0.3);
        }
        
        .btn-success {
            background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
        }
        
        .btn-success:hover {
            box-shadow: 0 10px 20px rgba(40, 167, 69, 0.3);
        }
        
        .status-card {
            background: white;
            border: 2px solid #e1e5e9;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
        }
        
        .status-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
        
        .status-indicator {
            display: inline-block;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 8px;
        }
        
        .status-success {
            background: #28a745;
        }
        
        .status-error {
            background: #dc3545;
        }
        
        .status-warning {
            background: #ffc107;
        }
        
        .message {
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 20px;
            display: none;
        }
        
        .message.success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .message.error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        .message.info {
            background: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
        }
        
        .grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
        }
        
        .result-box {
            background: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 15px;
            font-family: 'Courier New', monospace;
            white-space: pre-wrap;
            max-height: 200px;
            overflow-y: auto;
        }
        
        @media (max-width: 768px) {
            .content {
                padding: 20px;
            }
            
            .grid {
                grid-template-columns: 1fr;
            }
            
            .nav-bar {
                padding: 15px;
            }
            
            .nav-bar a {
                display: block;
                margin-bottom: 10px;
                margin-right: 0;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>许可管理系统</h1>
            <p>Sentinel LDK Licensing - 许可证检查与管理</p>
        </div>
        
        <div class="nav-bar">
            <a href="/" class="">🏠 首页</a>
            <a href="/license" class="active">🔐 许可管理</a>
            <a href="/users" class="">👥 用户管理</a>
        </div>
        
        <div class="content">
            <div id="message" class="message"></div>
            
            <div class="section">
                <h2>🔍 许可证检查</h2>
                <div class="grid">
                    <div>
                        <div class="form-group">
                            <label for="featureId">功能ID:</label>
                            <input type="number" id="featureId" value="0" placeholder="请输入功能ID">
                        </div>
                        <button class="btn" onclick="checkLicense()">检查许可证</button>
                        <button class="btn btn-secondary" onclick="clearResult()">清空结果</button>
                    </div>
                    <div>
                        <label>检查结果:</label>
                        <div id="licenseResult" class="result-box">等待检查...</div>
                    </div>
                </div>
            </div>
            
            <div class="section">
                <h2>📊 系统状态</h2>
                <div class="grid">
                    <div class="status-card">
                        <h3><span id="healthIndicator" class="status-indicator status-warning"></span>服务状态</h3>
                        <p id="healthStatus">检查中...</p>
                        <button class="btn btn-success" onclick="checkHealth()">刷新状态</button>
                    </div>
                    <div class="status-card">
                        <h3><span class="status-indicator status-success"></span>许可证服务</h3>
                        <p>Sentinel LDK 许可证验证服务</p>
                        <p><small>支持硬件和软件许可证</small></p>
                    </div>
                </div>
            </div>
            
            <div class="section">
                <h2>ℹ️ 使用说明</h2>
                <div class="status-card">
                    <h4>功能说明:</h4>
                    <ul style="margin-left: 20px; line-height: 1.8;">
                        <li><strong>许可证检查:</strong> 输入功能ID来检查对应的许可证状态</li>
                        <li><strong>功能ID 0:</strong> 默认功能，用于基本许可证验证</li>
                        <li><strong>系统状态:</strong> 显示当前许可证服务的运行状态</li>
                        <li><strong>实时监控:</strong> 支持实时检查许可证状态变化</li>
                    </ul>
                </div>
                <div class="status-card">
                    <h4>状态说明:</h4>
                    <ul style="margin-left: 20px; line-height: 1.8;">
                        <li><span class="status-indicator status-success"></span><strong>正常:</strong> 许可证验证成功</li>
                        <li><span class="status-indicator status-warning"></span><strong>警告:</strong> 许可证即将过期或有限制</li>
                        <li><span class="status-indicator status-error"></span><strong>错误:</strong> 许可证验证失败或不存在</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        // API 基础URL
        const API_BASE = '/api/license';
        
        // 显示消息
        function showMessage(text, type = 'success') {
            const messageEl = document.getElementById('message');
            messageEl.textContent = text;
            messageEl.className = `message ${type}`;
            messageEl.style.display = 'block';
            
            setTimeout(() => {
                messageEl.style.display = 'none';
            }, 5000);
        }
        
        // 检查许可证
        async function checkLicense() {
            const featureId = document.getElementById('featureId').value;
            const resultEl = document.getElementById('licenseResult');
            
            try {
                resultEl.textContent = '检查中...';
                
                const response = await fetch(`${API_BASE}/check?featureId=${featureId}`);
                const result = await response.text();
                
                resultEl.textContent = `功能ID: ${featureId}\n检查时间: ${new Date().toLocaleString('zh-CN')}\n结果: ${result}`;
                
                if (response.ok) {
                    showMessage(`许可证检查完成 (功能ID: ${featureId})`, 'success');
                } else {
                    showMessage('许可证检查失败', 'error');
                }
            } catch (error) {
                console.error('许可证检查失败:', error);
                resultEl.textContent = `检查失败: ${error.message}`;
                showMessage('许可证检查失败: 网络错误', 'error');
            }
        }
        
        // 清空结果
        function clearResult() {
            document.getElementById('licenseResult').textContent = '等待检查...';
        }
        
        // 检查健康状态
        async function checkHealth() {
            const statusEl = document.getElementById('healthStatus');
            const indicatorEl = document.getElementById('healthIndicator');
            
            try {
                statusEl.textContent = '检查中...';
                indicatorEl.className = 'status-indicator status-warning';
                
                const response = await fetch(`${API_BASE}/health`);
                const result = await response.text();
                
                if (response.ok) {
                    statusEl.textContent = result;
                    indicatorEl.className = 'status-indicator status-success';
                    showMessage('系统状态检查完成', 'success');
                } else {
                    throw new Error('健康检查失败');
                }
            } catch (error) {
                console.error('健康检查失败:', error);
                statusEl.textContent = `连接失败: ${error.message}`;
                indicatorEl.className = 'status-indicator status-error';
                showMessage('系统状态检查失败', 'error');
            }
        }
        
        // 页面加载完成后自动检查健康状态
        document.addEventListener('DOMContentLoaded', function() {
            checkHealth();
        });
        
        // 支持回车键触发许可证检查
        document.getElementById('featureId').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                checkLicense();
            }
        });
    </script>
</body>
</html>